package com.javaclimb.accounting.controller;

import com.alibaba.fastjson.JSONObject;
import com.javaclimb.accounting.po.Account;
import com.javaclimb.accounting.service.AccountService;
import com.javaclimb.accounting.utils.Consts;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/accounting")
public class AccountController {
    @Resource
    private AccountService accountService;

    /**
     * 查询电子用户余额
     * 查询接口   http://localhost:8888/accounting/account/queryBalance?userName=zhangsan
     * userName是用户名不是用户的真实姓名
     * 前端提供用户名
     */
    @RequestMapping(value = "/account/queryBalance",method = RequestMethod.GET)
    public Object queryBalance(String userName){
        JSONObject jsonObject = new JSONObject();
        Account account = accountService.queryBalance(userName);
        //有电子账户返回accountgg
        jsonObject.put(Consts.CODE,1);
        jsonObject.put(Consts.MSG,"查询成功");
        jsonObject.put("account",account);
        return jsonObject;
    }

}
